var HOST_IMG = 'http://mtg.hostingclients.myresellerhost.info/mtg';
function loadMore(event)
{
	a = event.target;
	splits = a.href.split('#')
	if (splits.length > 1)
	{
		key = splits[1];
		requestMoreModels(key);
	}
}
function requestMoreModels(key)
{
	$.getJSON('/api/model',{output:'json', last: key}, handlerLoadModel)
}
function handlerLoadModel(json, textStatus)
{
	$.each(json.models, function(i, model){
		$('ul.gallery').append(generateTopGirlDiv(model.username, model.avatar));
	})
	if(json.next == 1)
	{
		$('a#nextlink').attr('href', '#'+json.last.key);
	}
	else
	{
		$('a#nextlink').remove();
	}
}

function getImageUrl(username, imageUrl)
{
	var splits = imageUrl.split('/');
	var img = splits[splits.length -1];
	return HOST_IMG + '/'+username+'/'+img;
}

function generateTopGirlDiv(username, avatar)
{
	var imgname = getImageUrl(username, avatar);
	return $("<li></li>").addClass('topgirl').html('<a class="imgBorder" href="/model/'+username+'"><img class="avatar" width="65" height="70" src="'+imgname+'" alt="'+username+'"></a>');
}
